﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Entidades.Configuracion;
using DAL;

namespace LisBioGUIWPF
{
    /// <summary>
    /// Lógica de interacción para Configuracion.xaml
    /// </summary>
    public partial class Configuracion : Window
    {

        private LisBio lisBio;

        public Configuracion(LisBio lisBio)
        {
            InitializeComponent();

            this.lisBio = lisBio;

            this.Loaded += new RoutedEventHandler(Configuracion_Loaded);

            this.checkAcceso.IsChecked = this.lisBio.GodMode;
        }

        void Configuracion_Loaded(object sender, RoutedEventArgs e)
        {
            this.txtPassword.Focus();
        }

        private void txtPassword_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && txtPassword.Password.Equals(@"deitelgodmode"))
            {
                this.grid1.Visibility = Visibility.Visible;
            }
        }

        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            BaseXML baseXml = new BaseXML(this.txtSource.Text, this.txtCatalog.Text);
            ConfiguracionXML config = new ConfiguracionXML(baseXml, this.txtImagenes.Text);

            XmlOperations xml = new XmlOperations();
            xml.serialize(config, "config.xml");

            this.lisBio.PathImages = this.txtImagenes.Text;
            DAL.Funciones.actualizados = false;

            this.lisBio.notification("Configuracion Guardada");
            this.Close();
        }

        private void btnSeleccionar_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog open = new System.Windows.Forms.FolderBrowserDialog();

            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string path = @open.SelectedPath;
                this.txtImagenes.Text = path;
            }
        }

        private void btnAplicar_Click(object sender, RoutedEventArgs e)
        {
            if (((bool)checkAcceso.IsChecked))
            {
                this.lisBio.GodMode = true;
                this.lisBio.borderHuella.IsEnabled = true;
            }
            else
            {
                this.lisBio.GodMode = false;
                this.lisBio.borderHuella.IsEnabled = false;
            }
            this.Close();
        }

    }
}
